<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>vue.extend</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.common.dev.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.core.min.js"></script>
</head>
<body>
<div id="root">

</div>
<script>
    const loadingComponent = Vue.extend({
        template: '<div class="loading-content">{{msg}}</div>',
        props: {
            msg: {
                type: 'string',
                default: "loading",
                required: false
            }
        }
    })

    const Loading = () => {
        const div = document.createElement('div');
        div.setAttribute("id", "loading");
        document.body.appendChild(div);
        new loadingComponent({}).$mount("#loading")

        return () => {
            document.getElementById("loading").style.display = "none"
        }
    }
    Vue.prototype.$loading = Loading
    const vm = new Vue({
        el: "#root",
        template: `
          <div>
          <button @click="showLoading">start loading</button>
          </div>`,
        methods: {
            showLoading() {
                const hide = this.$loading();

                setTimeout(() => {
                    hide()
                }, 1500)
            }
        }
    })
</script>
</body>
</html>
